package com.github.cyf.mapper;

import com.github.cyf.domain.po.User;
import com.github.cyf.interceptor.encrypt.EncryptResult;
import com.github.cyf.interceptor.encrypt.impl.AESEncryptStrategy;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.context.annotation.Description;

import java.util.List;

/**
 * @author chenyifan
 * @create 2024-04-11 9:39
 */
@Mapper
public interface UserMapper {

    @Description("通过 id 获取用户")
    @Select("SELECT * FROM ${tableName} WHERE id = #{id} AND id = #{id}")
//    User getUserId(Long id, String tableName);
    User getUserId(@Param("id") Long id, @Param("tableName") String tableName);


    @Description("查询所有用户")
    @Select("SELECT * FROM t_user")
    List<User> getAllUser();

    @Description("通过 id 修改用户年龄")
    @Update("UPDATE t_user SET age = #{age} WHERE id = #{id}")
    void updateUserAgeById(@Param("id") Long id, @Param("age") Integer age);

    @Description("获取符合条件的用户")
    @EncryptResult(encryptStrategy = AESEncryptStrategy.class, fields = {"phone","password"})
    List<User> getUserByCondition(@Param("age") Integer age, @Param("sex") Integer sex, @Param("phone") String phone);
}
